<?php
         $server = new SoapServer(null, array('uri' =>'http://ligadonoenem.com/loja/path/servidor/'));  //'http://ligadonoenem.com/loja/path/servidor/'));         //
          
         
         function User($email,$part,$key,$nome=null,$sobre_nome=null){
  
                  $_HOST_SERVER_ = 'localhost';
                  $_DB_USER_     = 'ligado_loja';
                  $_DB_PASSWD_   = '345Senha';
                  $_DB_NAME_     = 'ligado_loja';
                  $_KEY_         = '1aa123';                 
//                  $_HOST_SERVER_ = 'mysql.cafeead.com';
//                  $_DB_USER_     = 'cafeead11';
//                  $_DB_PASSWD_   = 'a06g09b18';
//                  $_DB_NAME_     = 'cafeead11';
//                  $_KEY_         = '1aa123';
//                  $_HOST_SERVER_ = 'localhost';
//                  $_DB_USER_     = 'root';
//                  $_DB_PASSWD_   = '123';
//                  $_DB_NAME_     = 'prestashop13x';
//                  $_KEY_         = '1aa123';
             
               $_part = explode('@',$email);              
               $conbina = md5($part.$key);
               $_KEY    = md5($_part[0].$_KEY_);
            if($conbina  == $_KEY){      
                  
                  $erros = 1;
                  $link = mysql_connect($_HOST_SERVER_,$_DB_USER_,$_DB_PASSWD_);
               if (!$link){
                  $erros = 'Could not connect: ' . mysql_error();}
                  $sel = mysql_select_db($_DB_NAME_);
               if (!$sel){
                  $erros = 'selecao ';}

                  $SQL ='select * from ps_customer where email = "'.$email.'"';
                  $user_found = mysql_query($SQL);
                  $user = mysql_fetch_array($user_found);
                  $c = array('email'=>$user['email'],'senha'=>$user['passwd']);

             if($user['email'] == ''){

                  $c = '';
//               $SQL_insert = "INSERT INTO `ps_customer` (`id_gender`, `id_default_group`, `secure_key`, `email`,
//                              `passwd`, `last_passwd_gen`, `birthday`, `lastname`, `newsletter`, `ip_registration_newsletter`,
//                              `newsletter_date_add`, `optin`, `firstname`, `dni`, `active`, `deleted`, `date_add`, `date_upd`)
//                       VALUES (1, 1, 'c569a2a998c76f64f51330c59598f97f', '".$email."', '2e555ed3acc2396988f040ed20354327',
//                               '2012-03-26 17:24:40', NULL, '$sobre_nome', 0, NULL, NULL, 0, '$nome', NULL, 1, 0, '2012-03-26 23:24:40',
//                               '2012-04-01 03:02:53');";
//                $user_insert = mysql_query($SQL_insert);
//
//                  $SQL ='select * from ps_customer where email = "'.$email.'"';
//                  $user_found2 = mysql_query($SQL);
//                  $query_found = mysql_fetch_array($user_found2);
//                    $id = $query_found['id_customer'];
//
//               $SQL_address = "INSERT INTO `ps_address` (`id_country`, `id_state`, `id_customer`,
//                               `id_manufacturer`, `id_supplier`, `alias`, `company`, `lastname`, `firstname`,
//                               `address1`, `address2`, `postcode`, `city`, `other`, `phone`, `phone_mobile`,
//                               `date_add`, `date_upd`, `active`, `deleted`)
//                       VALUES (58, 122, ".$id.", 0, 0, 'asas', '', '$sobre_nome', '$nome', 'rua tal', 'centro', '8899999', 'Capitalx',
//                                '', '', '000000', '2012-04-11 04:47:43', '2012-04-11 04:47:43', 1, 0);";
//                $rel_address = mysql_query($SQL_address);
//
//
//                $SQL_group = "INSERT INTO `ps_customer_group` (`id_customer,id_group`)
//                       VALUES (".$id.",1);";
//                $rel_group = mysql_query($SQL_group);
//
//                  $SQL ='select * from ps_customer where email = "'.$email.'"';
//                  $user_found = mysql_query($SQL);
//                  $query = mysql_fetch_array($user_found);
//                  $c = array('email'=>$query['email'],'senha'=>$query['passwd']);
//
//
             }
               mysql_close($link);    

            }else
                $c = '001  -  KEY error';
               
           return $c;
         }         
         
                
          $server->addFunction("User");
          
if ($_SERVER["REQUEST_METHOD"]== "POST") {
		$server->handle();
} else {
	$functions = $server->getFunctions();
	foreach ($functions as $func) {
		print $func. "<br>";
	}
}


//print_r(User());

?>
